package com.mark.controller.seller;

import com.github.pagehelper.PageInfo;
import com.mark.common.ServerResponse;
import com.mark.controller.common.CurrentUser;
import com.mark.pojo.User;
import com.mark.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * Created by Choisaaaa on 2018/5/22.
 * 卖家处理订单
 */

@Controller
@RequestMapping("/seller/order")
public class SellerOrderController {
    @Autowired
    private IOrderService iOrderService;

    //1.店家查看接收到的订单
    @RequestMapping(value = "list.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse SellerList(HttpServletRequest httpServletRequest,
                                     @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                     @RequestParam(value = "pageSize",defaultValue = "10") int pageSize){
        ServerResponse response = CurrentUser.getCurrentUser(httpServletRequest);
        if (!response.isSuccess()){
            return response;
        }
        User currentUser = (User) response.getData();
        return iOrderService.getSellerOrderList(currentUser.getId(),pageNum,pageSize);
    }

    //2.店家查看订单详情
    @RequestMapping(value = "detail.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse SellerDetail(HttpServletRequest httpServletRequest,Long orderNo){
        ServerResponse response = CurrentUser.getCurrentUser(httpServletRequest);
        if (!response.isSuccess()){
            return response;
        }
        User currentUser = (User) response.getData();
        return iOrderService.getOrderDetail(null,orderNo,currentUser.getId());
    }

    //3.店家发货
    @RequestMapping(value = "send_goods.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<String> orderSendGoods(Long orderNO,HttpServletRequest httpServletRequest){
        ServerResponse response = CurrentUser.getCurrentUser(httpServletRequest);
        if (!response.isSuccess()){
            return response;
        }
        User currentUser = (User) response.getData();
        return iOrderService.sellerSendGoods(orderNO,currentUser.getId());
    }

    //4.店家搜索订单
    @RequestMapping(value = "search.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> orderSearch(HttpSession session, Long orderNo, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                                @RequestParam(value = "pageSize",defaultValue = "10")int pageSize,
                                                HttpServletRequest httpServletRequest){
        ServerResponse response = CurrentUser.getCurrentUser(httpServletRequest);
        if (!response.isSuccess()){
            return response;
        }
        User currentUser = (User) response.getData();
        return iOrderService.sellerSearchOrder(orderNo,pageNum,pageSize,currentUser.getId());
    }

    //5.店家搜索待发货订单
    @RequestMapping(value = "searchPayed.do",method = RequestMethod.POST)
    @ResponseBody
    public ServerResponse<PageInfo> searchOrderPayed(HttpSession session, @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                                                @RequestParam(value = "pageSize",defaultValue = "10")int pageSize,
                                                HttpServletRequest httpServletRequest){
        ServerResponse response = CurrentUser.getCurrentUser(httpServletRequest);
        if (!response.isSuccess()){
            return response;
        }
        User currentUser = (User) response.getData();
        return iOrderService.searchOrderPayed(pageNum,pageSize,currentUser.getId());
    }

}
